<?php

namespace Drupal\s_announcement\ViewsController;

use Drupal\s_announcement\ViewsController\handler\field\SAnnouncementEditLinkViewsField;
use Drupal\s_announcement\ViewsController\handler\field\SAnnouncementStatusViewsField;
use Drupal\s_announcement\ViewsController\handler\field\SAnnouncementStickyViewsField;
use Drupal\s_announcement\ViewsController\handler\filter\SAnnouncementStatusViewsFilter;
use Drupal\s_announcement\ViewsController\handler\filter\SAnnouncementStickyViewsFilter;
use EntityDefaultViewsController;


class SAnnouncementViewsController extends EntityDefaultViewsController {

  public function views_data() {
    $data = parent::views_data();
    if (!empty($this->info['base table'])) {
      $table = $this->info['base table'];
      $info = [];

      $info[$table]['edit_link'] = [
        'title' => t('编辑'),
        'help' => t('编辑.'),
        'field' => [
          'handler' => SAnnouncementEditLinkViewsField::class,
        ],
      ];
      $info[$table]['sticky'] = [
        'title' => '推荐到首页 0 否 1 是',
        'help' => '推荐到首页 0 否 1 是',
        'real field' => 'sticky',
        'field' => [
          'handler' => SAnnouncementStickyViewsField::class,
        ],
        'filter' => [
          'handler' => SAnnouncementStickyViewsFilter::class,
        ],
      ];
      $info[$table]['status'] = [
        'title' => '状态 0 关闭 1 开启',
        'help' => '状态 0 关闭 1 开启',
        'real field' => 'status',
        'field' => [
          'handler' => SAnnouncementStatusViewsField::class,
        ],
        'filter' => [
          'handler' => SAnnouncementStatusViewsFilter::class,
        ],
      ];
      $data = drupal_array_merge_deep($data, $info);
    }
    return $data;
  }
}
